using System.ComponentModel.DataAnnotations;

namespace MonitorPlatform.Data.Entities
{
    public class Session : BaseEntity
    {
        [Key]
        [StringLength(100)]
        public string SessionId { get; set; } = string.Empty;

        [Required]
        [StringLength(50)]
        public string AppId { get; set; } = string.Empty;

        [StringLength(100)]
        public string? UserId { get; set; }

        public DateTime StartTime { get; set; }
        public DateTime? EndTime { get; set; }

        public int Duration => EndTime.HasValue 
            ? (int)(EndTime.Value - StartTime).TotalSeconds 
            : (int)(DateTime.UtcNow - StartTime).TotalSeconds;

        // Page Information
        [StringLength(500)]
        public string? EntryPage { get; set; }

        [StringLength(500)]
        public string? ExitPage { get; set; }

        public int PageViews { get; set; } = 0;

        [StringLength(500)]
        public string? Referrer { get; set; }

        // Device and Browser Information
        [StringLength(500)]
        public string? UserAgent { get; set; }

        [StringLength(50)]
        public string? DeviceType { get; set; }

        [StringLength(50)]
        public string? Os { get; set; }

        [StringLength(50)]
        public string? Browser { get; set; }

        [StringLength(20)]
        public string? BrowserVersion { get; set; }

        [StringLength(20)]
        public string? ScreenResolution { get; set; }

        [StringLength(20)]
        public string? ViewportSize { get; set; }

        // Network Information
        [StringLength(50)]
        public string? Ip { get; set; }

        [StringLength(50)]
        public string? Country { get; set; }

        [StringLength(50)]
        public string? Region { get; set; }

        [StringLength(50)]
        public string? City { get; set; }

        [StringLength(20)]
        public string? ConnectionType { get; set; }

        // Session Quality Metrics
        public int ErrorCount { get; set; } = 0;
        public double? AverageResponseTime { get; set; }
        public bool IsBounce { get; set; } = false;

        // Additional Data
        public string? CustomAttributes { get; set; }

        // Navigation properties
        public virtual Application Application { get; set; } = null!;
    }
} 